import * as types from '../constants/ActionTypes';

export default function findpwd(state = [], action = {}) {
    const {
        type, payload
    } = action;

    switch (type) {
        case types.FINDPWD:
            return { ...payload };
        case types.FINDPWD_SUCCESS:
            let successInfo = null;
            if (payload.results && payload.results.length) {
                //payload.status["0","1","2","3","4"]=>
                //["系统错误","非系统用户","基础信息表有数据，但无登录信息","已经注册，没有密码","已经注册，有密码"]
                successInfo = {
                    findpwd_status : 1,
                    message :　"手机号码验证成功"
                };
            }else{
                successInfo = {
                    findpwd_status: 0,
                    message: "手机号码验证失败"
                };
            }
            return {
               ...state,
               ...successInfo
            };   
        case types.FINDPWD_FAILURE:
            let failureInfo = {
                findpwd_status: -1,
                message: payload.message||'网络连接失败'
            };
            return {
               ...state,
               ...failureInfo
            };

        //========================================================

        case types.FINDPWD2:
            return { ...state };

        case types.FINDPWD2_SUCCESS:
            let successInfo2 = {
                findpwd2_status : 1,
                message : "密码找回成功"
            };
            return {
               ...state,
               ...successInfo2
            };   
        case types.FINDPWD2_FAILURE:
            let failureInfo2 = {
                findpwd2_status : -1,
                message: payload.message||'网络连接失败'
            };
            return {
               ...state,
               ...failureInfo2
            };  
        default:
            return state;
    }
}